﻿using infoMECHANICA.NHibernateORM.TestMappings;
using NHibernate.Criterion;

namespace infoMECHANICA.NHibernateORM.ExampleProgram
{
    /// <summary>
    /// See http://www.codeplex.com/nhcb/Wiki/View.aspx?title=REFACTORABLE_NHIBERNATE_CRITERIA&referringTitle=Home for details
    /// </summary>
    public class Example7 : IExample
    {
        #region IExample Members

        public string Title
        {
            get { return "Example 7 - Refactorable NHibernate Criteria"; }
        }

        public DetachedCriteria ComposeCriteria()
        {
            // build criteria in NHCB way
            EmployeeRec employeeRec = new EmployeeRec();
            DetachedCriteria criteria = DetachedCriteria.For<Employee>()
                .Add(Expression.Or(employeeRec.FirstName.AsEqCriterion("John"),
                                   employeeRec.Salary.AsGtCriterion(700)))
                .AddOrder(employeeRec.FirstName.AsOrderAsc());

            return criteria;
        }

        #endregion
    }
}
